package com.atguigu.study.config;

import com.atguigu.study.listener.TestChatModelListener;
import dev.langchain4j.model.chat.ChatModel;
import dev.langchain4j.model.openai.OpenAiChatModel;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.time.Duration;
import java.util.List;

/**
 * @auther zzyy
 * @create 2025-03-11 17:43
 */
@Configuration
public class ChatModelConfig {
    @Bean
    public ChatModel chatModel() {
        return OpenAiChatModel.builder()
            .apiKey(System.getenv("LANGCHAIN4J_KEY"))
            .modelName("qwen-turbo")
            .baseUrl("https://dashscope.aliyuncs.com/compatible-mode/v1")
            // 日志界别设置为debug才有效
            .logRequests(true)
            .logResponses(true)
            // 监听器
            .listeners(List.of(new TestChatModelListener()))
            // 重试机制（次数）默认重试2次
            .maxRetries(1)
            // 设置10秒超时
            .timeout(Duration.ofSeconds(10))
            .build();
    }
}
 
 
